<template>
  <div>
    <el-dialog title="编辑会员" :visible.sync="isShow" :before-close="cancel" center>
      <el-form :model="memberForm" ref="memberRef" :rules="rules">
        <el-form-item prop="phone" label="手机号" :label-width="formLabelWidth">
          <el-input v-model="memberForm.phone" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item prop="nickname" label="昵称" :label-width="formLabelWidth">
          <el-input v-model="memberForm.nickname" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="密码" :label-width="formLabelWidth">
          <el-input v-model="memberForm.password" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="状态" :label-width="formLabelWidth">
          <el-tooltip :content="'Switch value: ' + value" placement="top">
            <el-switch
              v-model="memberForm.status"
              active-color="#13ce66"
              inactive-color="#ff4949"
              :active-value="1"
              :inactive-value="2"
            >
            </el-switch>
          </el-tooltip>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="add">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { memberInfo, memberEdit } from "../../request/api.js";
export default {
  props: ["isShow"],
  data() {
    return {
      memberForm: {
        uid: "", //会员编号，必填项
        nickname: "", //昵称
        phone: "", //手机号
        password: "", //密码
        status: 1, //状态1正常2禁用
      },
      value: "1",
      formLabelWidth: "80px",
      rules: {
        phone: [
          { required: true, message: "请输入手机号", trigger: "blur" },
          { min: 2, max: 11, message: "长度在 2 到 11 个字符", trigger: "blur" },
        ],
        nickname: [
          { required: true, message: "请输入昵称", trigger: "change" },
          { min: 2, max: 6, message: "长度在 2 到 6 个字符", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    // 封装一个去取消事件
    cancel() {
      this.$emit("cancel", false);
    },
    // 封装一个数据回显
    lookup(uid) {
      memberInfo({ uid }).then((res) => {
        // console.log(res);
        this.memberForm = res.list;
        this.memberForm.uid = uid;
      });
    },
    add() {
      this.$refs.memberRef.validate((val) => {
        if (val) {
          memberEdit(this.memberForm).then((res) => {
            console.log(res);
            if (res.code == 200) {
              // 关闭弹框
              this.cancel();
              // 重新调用列表 触发行动
              // this.$store.dispatch("menu/getMenuListActions");
              this.$store.dispatch("member/getMemberListActions");
              this.$message.success(res.msg);
            } else {
              this.$message.error(res.msg);
            }
          });
        }
      });
    },
  },
  mounted() {},
  watch: {},
  computed: {},
  filters: {},
  components: {},
};
</script>
<style scoped></style>
